﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Data;

namespace Atlantyda
{
    public partial class LoginForm : Form
    {
        private MainForm parent;

        public LoginForm(MainForm parent)
        {
            InitializeComponent();
            this.SetParent(parent);
        }

        private void cancelBtn_Click(object sender, EventArgs e)
        {
            this.CloseForm();
        }

        public void CloseForm()
        {
            this.Close();
        }

        private void loginBtn_Click(object sender, EventArgs e)
        {
            Agent.Address = AddressTxt.Text;
            Agent.Port = Convert.ToInt16(PortTxt.Text);
            Agent.GroupName = GroupTxt.Text;
            Agent.Password = PassTxt.Text;
            Agent.WorldName = WorldTxt.Text;
            Agent.AgentName = AgentTxt.Text;
            Agent.WebAddress = WebAddressTxt.Text;
            try {
                if (Agent.Connect()) {
                    this.CloseForm();
                    Agent.MainForm.ShowLoadingBox();
                    Agent.ShowMap();
                }
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message, "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }

        public void SetParent(MainForm parent)
        {
            this.parent = parent;
        }

        public MainForm GetParent()
        {
            return this.parent;
        }

        private void PortTxt_Leave(object sender, EventArgs e)
        {
            if (PortTxt.Text == "") {
                PortTxt.Text = "0";
            }
        }
    }
}
